<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class Driver
 * Desc  司机Model
 * Create on 2024/10/26 17:45
 * Create by wangyafang
 */

namespace app\api\model\wddj\driver;


use think\Model;

class Driver extends Model
{
// 表名
    protected $name = 'wddj_driver';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    public static function getDriverBaseInfo($id)
    {

        $driverObj = self::where('d.id',$id)
            ->alias('d')
            ->join('wddj_certified_driving_agent certified','d.wechat_id = certified.wechat_id')
            ->field('certified.name,d.wechat_id,d.driver_lng,d.driver_lat')
            ->find();

        $acceptance_number = (new Order())->where('state','in',['accepted','in_progress','adjusting','refunded','awaiting_payment','completed'])
        ->where('driver_id',$id)
        ->where('driver_wechat_id',$driverObj->wechat_id)
        ->count();
        return array(
            'name'=>mb_substr($driverObj['name'], 0, 1, 'UTF-8').'师傅',
            'acceptance_number'=>$acceptance_number,
            'lng'=>$driverObj['driver_lng'],
            'lat'=>$driverObj['driver_lat'],
            'avatar'=>wddj_full_url('/assets/addons/wddj/img/driver.png'),
        );

    }

    public static function getMobile($id)
    {
        $mobile = self::where('d.id',$id)
            ->alias('d')
            ->join('wddj_user_wechat wechat','d.wechat_id = wechat.id')
            ->value('wechat.mobile');
        return $mobile;
    }
}



 